//
//  GuangMasterViewCell.m
//  Shopping
//
//  Created by qianfeng on 16/1/16.
//  Copyright © 2016年 qianfeng. All rights reserved.
//

#import "GuangMasterViewCell.h"

#import "GuangMasterModel.h"
#import "UIImageView+WebCache.h"

@interface GuangMasterViewCell ()

@property(strong , nonatomic) UIView * infoView;
@end

@implementation GuangMasterViewCell

- (void)awakeFromNib {
    
    int x = 0;
    for (ItemsModel * items in self.model.items) {
        
        UIImageView *photoImageView = [[UIImageView alloc] init];
        photoImageView.frame = CGRectMake(20, CGRectGetMaxY(self.imageIcon.frame) + 10, 80, 100);
        [photoImageView sd_setImageWithURL:[NSURL URLWithString:items.skuImgurl]];
        [self.infoView addSubview:photoImageView];
        
        UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(photoImageView.frame) + 10, 80, 20)];
        titleLabel.text = items.skuLinkName;
        [self.infoView addSubview:titleLabel];
        
        UILabel * pricaLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(titleLabel.frame) + 5, 80, 15)];
        pricaLabel.text = [NSString stringWithFormat:@"¥%d",items.price.intValue];
        
        [self.infoView addSubview:pricaLabel];
        
        [self addSubview:self.infoView];
        x++;

    }
    


}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    GuangMasterViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"masterCell"];
    
    if (cell == nil) {
        cell = [[GuangMasterViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"masterCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }

    return cell;
}


-(void)setModel:(GuangMasterModel *)model
{
    _model = model;
    
    for (UIView * view in self.contentView.subviews) {
        if(view.tag == 222) continue;
        [view removeFromSuperview];
    }
    
    [self.imageIcon sd_setImageWithURL:[NSURL URLWithString:model.imgurl] placeholderImage:[UIImage imageNamed:@"loading"]];
    int x = 0;
    for (ItemsModel * items in model.items) {
        
        UIImageView *photoImageView = [[UIImageView alloc] init];
        photoImageView.frame = CGRectMake(20 + (100 * x) , CGRectGetMaxY(self.imageIcon.frame) + 10, 80, 100);
        [photoImageView sd_setImageWithURL:[NSURL URLWithString:items.skuImgurl]];
        [self.contentView addSubview:photoImageView];
        
        UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20 + (100 * x), CGRectGetMaxY(photoImageView.frame) + 10, 80, 20)];
        titleLabel.text = items.skuLinkName;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:titleLabel];
        
        UILabel * pricaLabel = [[UILabel alloc]initWithFrame:CGRectMake(20 + (100 * x), CGRectGetMaxY(titleLabel.frame) + 5, 80, 15)];
        pricaLabel.text = [NSString stringWithFormat:@"¥%d",items.price.intValue];
        pricaLabel.textAlignment = NSTextAlignmentCenter;
        pricaLabel.font = [UIFont systemFontOfSize:10];
        pricaLabel.tintColor = [UIColor grayColor];
        [self.contentView addSubview:pricaLabel];
        
        x++;
        
    }

    
    
}
@end
